<?
/*include_once '/var/www/html/new/com.inc.php';
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
*/


include("common/header.html");
include("common/left.html");
include("common/page.php");
$pageSize=$_GET['pageSize']?$_GET["pageSize"]:20;
$currentPage=$_GET["currentPage"]?$_GET["currentPage"]:1;
$offset=($currentPage-1)*$pageSize;
if($type=$_GET['type']){
    $where="where access_action=$type";
}else{
    $where="where 1=1";
};
$btime=$_GET['btime'];
$etime=$_GET['etime'];
if($days=abs($_GET['days'])){
    $btime=$_SERVER['REQUEST_TIME']-3600*24*$days;
    $btime=date("Y-m-d",$btime);
    $etime=date("Y-m-d");
}
if($btime){
    $where.=" and access_time>='$btime 00:00:00'";
}
if($etime){
    $where.=" and access_time<='$etime 23:59:59'";
}
$pre = "select count(*) as total from pft_access_log {$where}";
$GLOBALS['le']->query($pre);
$GLOBALS['le']->fetch_assoc();
$count=$GLOBALS['le']->f("total");

var_dump($_SERVER['HTTP_REFERER']);
echo "<br/>";
//计算出上一页的currentPage并且计算出是否上下一页
$begin=strpos(($_SERVER['HTTP_REFERER']),"currentPage")+12;
$length=strpos(($_SERVER['HTTP_REFERER']),"pageSize")-$begin-1;
$lcPage=substr($_SERVER['HTTP_REFERER'],$begin,$length);
$res=$lcPage-$currentPage;
echo $res;
$r=array();
$arr=array(1=>"退款",2=>"提现",3=>"修改模板");
$mod=$count%20;
$idmax=$count-($currentPage-1)*20;
$idmin=$count-$currentPage*20;
switch($res){
    case 1://上一页
        echo "a";
        $str="select mid,access_ip,access_time,access_note,access_action from pft_access_log $where and id>$idmax order by id asc limit $pageSize";
        $a=microtime();
        $GLOBALS['le']->query($str);
        $b=microtime()-$a;
        echo $b;
        $arr1=array();
        while($row=$GLOBALS['le']->fetch_assoc()){
            $arr1[]=$row;
        }
        arsort($arr1);
        foreach($arr1 as $val){
            $r[]=$val;
        }
        break;
    case -1:
        $str="select mid,access_ip,access_time,access_note,access_action from pft_access_log $where and id<$idmin order by id desc limit $pageSize";
        $a=microtime();
        $GLOBALS['le']->query($str);
        $b=microtime()-$a;
        echo $b;
        while($row=$GLOBALS['le']->fetch_assoc()){
            $r[]=$row;
        }
        echo "b";
        break;
    default:
        echo "c";
        $str="select mid,access_ip,access_time,access_note,access_action from pft_access_log $where order by id desc limit $offset,$pageSize";
        $a=microtime();
        $GLOBALS['le']->query($str);
        $b=microtime()-$a;
        echo $b;
        while($row=$GLOBALS['le']->fetch_assoc()){
            $r[]=$row;
        }
        break;
}
    $a=microtime();
    $GLOBALS['le']->query($str);
    $b=microtime()-$a;
    echo $b;


?>
    <script src="js/Calendar.js" type="text/javascript"></script>
    <link href="css/page.css" rel="stylesheet" type="text/css" />
	<script language="javascript" src="http://www.12301.cc/js/WdatePicker.js"></script>
    <style>
        .orange{color:orange;}
        .green{color:green;}
        .red{color:red;}
        #right .notice{ margin-bottom: 10px; margin-top: 10px; padding: 20px; border:1px solid #ccc}
        #right .notice span{margin-right:20px}
        #right .time{ width:100px; border:1px solid #7F9DB9; height:18px; background:url("images/rili.png") no-repeat right center #FFFFFF;}
        .record table{ width:100%; margin-bottom:20px;}
        .record th{ background: none repeat scroll 0 0 #F3FAFF;border-bottom: 1px solid #DDEEFB;border-top: 1px solid #DDEEFB;height: 27px;line-height: 27px;text-align: center;}
        .record td{ border-bottom: 1px dashed #DDDDDD;line-height: 20px;padding: 10px 0;text-align: center;}
        .butbg{background:url(../images/search.png) no-repeat 0 0; cursor: pointer;height: 30px;width: 80px;border:none;}
    </style>
    <!--提现记录-->

    <div id="right" class="r_content"><!--BEGIN OF RIGHT-->
        <h3 class="mc_title">
            <span class="mctit_1"><span class="mctit_2">系统操作日志</span></span>
        </h3>
        <div class="notice">
            <form action="" method="GET">
                <span class="type">操作类型：</span>
                <select name="type">
                    <option value="">请选择</option>
                    <?foreach($arr as $key => $val):?>
                        <option value="<?=$key?>" <?if($_GET['type']==$key)echo 'selected="selected"'?>><?=$val?></option>
                    <?endforeach;?>
                </select>
                <span>修改日期：<input type="text" class="time" data-t="bt" id="txtStartTime"  value="<?=$btime?>" name="btime" /> 至 <input type="text" class="time" data-t="et" id="txtEndTime" name="etime"  value="<?=$etime?>"/></span><i> </i>
				<span>

					<a href="?days=7" class="monrea <?=($days==7)?"cuream":""?>">最近7天</a>
					<a href="?days=30" class="monrea <?=($days==30)?"cuream":""?>">最近30天</a></span>
                <span><input type="submit" value=" " class="butbg" /></span>
            </form>
        </div>
        <div class="record">
            <table>
                <tr class="header">
                    <th class="col1">序号</th>
                    <th class="col2">操作ID</th>
                    <th class="col3">操作时间</th>
                    <th class="col4">操作类型</th>
                    <th class="col5">操作IP</th>
                    <th class="col6">备注</th>

                </tr>
                <?foreach($r as $key => $row){?>
                    <tr class="<?=(++$i%2==0)?"odd":"even"?>">
                        <td class="col1"><?=($currentPage-1)*20+$key+1?></td>
                        <td class="col2"><?=$row['mid']?></td>
                        <td class="col3">
						<span title="<?=$row['access_time']?>">
							<?=substr($row['access_time'],0,16)?>
						</span>
                        </td>
                        <td class="col4"><?=$arr[$row['access_action']]?></td>
                        <td class="col5"><a href="http://www.ip.cn/index.php?ip=<?=$row['access_ip']?>" target="_blank">
                        <?=$row['access_ip'];?></a></td>
                        <td class="col6"><?=$row['access_note']?></td>

                    </tr>
                <?}?>
                <?if(count($r)==0){?>
                    <tr><td style="text-align:left; padding-left:50px;" colspan='9'>无相关记录</td></tr>
                <?}?>
            </table>
            <?
            if($count>0)
            {page($count,$currentPage,$pageSize);}?>
        </div>
    </div><!--EOF RIGHT-->
<script>
$("#txtStartTime").bind("click focus", function () {  
	
		   var endtimeTf = $dp.$('txtEndTime');             
		   WdatePicker({                            
			   maxDate: '#F{$dp.$D(\'txtEndTime\')}',      
			   dateFmt: "yyyy-MM-dd",              
			   onpicked: function () { endtimeTf.focus(); }          
				});         
		   });          
		   $("#txtEndTime").bind("click focus", function () {       
				WdatePicker({           
				   minDate: '#F{$dp.$D(\'txtStartTime\')}', 
				   dateFmt: "yyyy-MM-dd"       
			   });         
		   });
</script>
<?include("common/footer.html");?>